﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace TestEffectiveCS
{
    class Test14
    {
        public class MyClass1
        {
            private ArrayList _coll;
            private readonly string _name;

            public MyClass1()
                : this(0, "")
            {
            }

            public MyClass1(int initialCount)
                : this(initialCount, "")
            {
            }

            public MyClass1(int initialCount, string name)
            {
                _coll = (initialCount > 0) ?
                    new ArrayList(initialCount) :
                    new ArrayList();
                _name = name;
            }
        }

        public class MyClass2
        {
            private ArrayList _coll;
            private readonly string _name;

            public MyClass2()
            {
                commonConstructor(0, "");
            }

            public MyClass2(int initialCount)
            {
                commonConstructor(initialCount, "");
            }

            public MyClass2(int initialCount, string name)
            {
                commonConstructor(initialCount, name);
            }

            private void commonConstructor(int initialCount, string name)
            {
                _coll = (initialCount > 0) ?
                    new ArrayList(initialCount) :
                    new ArrayList();
                //错误，在构造器之外更改_name
                //_name = name;
            }
        }

        public Test14()
        {
        }
    }
}
